load("//src/starkware/cairo/lang/compiler:vars.bzl", "IS_COMPILER_PYPY")
load("//bazel_utils/python:defs.bzl", "requirement")
load("//bazel_utils:python.bzl", "py_exe", "pytest_test")
load("//src/starkware/cairo:vars.bzl", "CAIRO_LANG_VENV_ADDITIONAL_LIBS")

py_exe(
    name = "cairo_compile_exe",
    is_pypy = IS_COMPILER_PYPY,
    module = "starkware.cairo.lang.compiler.cairo_compile",
    deps = [
        "cairo_compile_lib",
        "//src/starkware/cairo/bootloaders:cairo_bootloader_generate_fact_lib",
        "//src/starkware/cairo/bootloaders:cairo_hash_program_lib",
        "//src/starkware/cairo/common:cairo_common_lib",
        "//src/starkware/cairo/lang/scripts:cairo_script_lib",
        "//src/starkware/cairo/lang/vm:cairo_run_lib",
    ] + CAIRO_LANG_VENV_ADDITIONAL_LIBS,
)

package(default_visibility = ["//visibility:public"])

py_library(
    name = "cairo_compile_lib",
    srcs = [
        "__init__.py",
        "assembler.py",
        "cairo_compile.py",
        "cairo_format.py",
        "const_expr_checker.py",
        "constants.py",
        "debug_info.py",
        "encode.py",
        "error_handling.py",
        "expression_evaluator.py",
        "expression_simplifier.py",
        "expression_transformer.py",
        "fields.py",
        "filter_unused_identifiers.py",
        "identifier_definition.py",
        "identifier_manager.py",
        "identifier_manager_field.py",
        "identifier_utils.py",
        "import_loader.py",
        "injector.py",
        "instruction.py",
        "instruction_builder.py",
        "location_utils.py",
        "module_reader.py",
        "offset_reference.py",
        "parser.py",
        "parser_transformer.py",
        "program.py",
        "proxy_identifier_manager.py",
        "references.py",
        "resolve_search_result.py",
        "scoped_name.py",
        "substitute_identifiers.py",
        "type_casts.py",
        "type_system.py",
        "type_system_visitor.py",
        "type_utils.py",
        "unique_name_provider.py",
        "//src/starkware/cairo/lang/compiler/ast:__init__.py",
        "//src/starkware/cairo/lang/compiler/ast:aliased_identifier.py",
        "//src/starkware/cairo/lang/compiler/ast:arguments.py",
        "//src/starkware/cairo/lang/compiler/ast:bool_expr.py",
        "//src/starkware/cairo/lang/compiler/ast:cairo_types.py",
        "//src/starkware/cairo/lang/compiler/ast:code_elements.py",
        "//src/starkware/cairo/lang/compiler/ast:expr.py",
        "//src/starkware/cairo/lang/compiler/ast:expr_func_call.py",
        "//src/starkware/cairo/lang/compiler/ast:formatting_utils.py",
        "//src/starkware/cairo/lang/compiler/ast:instructions.py",
        "//src/starkware/cairo/lang/compiler/ast:module.py",
        "//src/starkware/cairo/lang/compiler/ast:node.py",
        "//src/starkware/cairo/lang/compiler/ast:notes.py",
        "//src/starkware/cairo/lang/compiler/ast:parentheses_expr_wrapper.py",
        "//src/starkware/cairo/lang/compiler/ast:particle.py",
        "//src/starkware/cairo/lang/compiler/ast:rvalue.py",
        "//src/starkware/cairo/lang/compiler/ast:types.py",
        "//src/starkware/cairo/lang/compiler/ast:visitor.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:__init__.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:auxiliary_info_collector.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:compound_expressions.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:default_pass_manager.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:dependency_graph.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:directives.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:flow.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:identifier_aware_visitor.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:identifier_collector.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:if_labels.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:local_variables.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:memento.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:pass_manager.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:preprocess_codes.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:preprocessor.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:preprocessor_error.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:preprocessor_utils.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:reg_tracking.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:struct_collector.py",
        "//src/starkware/cairo/lang/compiler/preprocessor/bool_expr:__init__.py",
        "//src/starkware/cairo/lang/compiler/preprocessor/bool_expr:errors.py",
        "//src/starkware/cairo/lang/compiler/preprocessor/bool_expr:lowering.py",
    ],
    data = [
        "cairo.ebnf",
        "//src/starkware/cairo/lang/compiler/lib:registers.cairo",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//src/starkware/cairo/lang:cairo_constants_lib",
        "//src/starkware/cairo/lang:cairo_version_lib",
        "//src/starkware/python:starkware_expression_string_lib",
        "//src/starkware/python:starkware_python_utils_lib",
        "//src/starkware/starkware_utils:starkware_dataclasses_utils_lib",
        requirement("lark"),
        requirement("marshmallow"),
        requirement("marshmallow_enum"),
        requirement("marshmallow_dataclass"),
        requirement("marshmallow_oneofschema"),
    ],
)

py_exe(
    name = "cairo_format",
    module = "starkware.cairo.lang.compiler.cairo_format",
    deps = [
        "cairo_compile_lib",
    ],
)

py_library(
    name = "cairo_compile_test_utils_lib",
    srcs = [
        "test_utils.py",
        "//src/starkware/cairo/lang/compiler/ast:ast_objects_test_utils.py",
        "//src/starkware/cairo/lang/compiler/preprocessor:preprocessor_test_utils.py",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "cairo_compile_lib",
        "//src/starkware/python:starkware_python_utils_lib",
    ],
)

pytest_test(
    name = "cairo_compile_test",
    srcs = [
        "assembler_test.py",
        "ast_objects_test.py",
        "cairo_compile_test.py",
        "conftest.py",
        "debug_info_test.py",
        "encode_test.py",
        "error_handling_test.py",
        "expression_evaluator_test.py",
        "expression_simplifier_test.py",
        "filter_unused_identifiers_test.py",
        "identifier_definition_test.py",
        "identifier_manager_field_test.py",
        "identifier_manager_test.py",
        "identifier_utils_test.py",
        "import_loader_test.py",
        "injector_test.py",
        "instruction_builder_test.py",
        "instruction_test.py",
        "module_reader_test.py",
        "offset_reference_test.py",
        "parser_errors_test.py",
        "parser_test.py",
        "parser_test_utils.py",
        "proxy_identifier_manager_test.py",
        "references_test.py",
        "resolve_search_result_test.py",
        "scoped_name_test.py",
        "type_casts_test.py",
        "type_system_visitor_test.py",
        "type_utils_test.py",
        "unique_name_provider_test.py",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":cairo_compile_lib",
        ":cairo_compile_test_utils_lib",
        "//src/starkware/cairo/lang:cairo_constants_lib",
        "//src/starkware/cairo/lang/vm:cairo_vm_test_utils_lib",
        "//src/starkware/python:starkware_python_test_utils_lib",
        "//src/starkware/python:starkware_python_utils_lib",
        "//src/starkware/starkware_utils:starkware_dataclasses_utils_lib",
        requirement("marshmallow_dataclass"),
    ],
)
